package com.zxy.basic.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author zhangyinglei
 * @date 2019/7/10 16:01
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Value("${swagger.enable:true}")
    private boolean enableSwagger;

    private ApiInfo apiInfo(String title) {
        return new ApiInfoBuilder().title(title)
                .description("接口文档说明")
                .contact(new Contact("果果科技", "", "devops@guoguokeji.com.cn"))
                .version("1.0")
                .build();
    }

    /**
     * 按照路由来分组
     *
     * @return
     */
    @Bean
    public Docket index() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("智慧教育-用户管理"))
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/index/**"))
                .build()
                .groupName("智慧教育-用户管理-接口文档V1.0")
                .pathMapping("/")
                .enable(enableSwagger);
    }


}
